package com.spzx.common.core.config;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.context.SecurityContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenFeignConfig {
    @Bean
    public RequestInterceptor userInfoRequestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                requestTemplate.header(SecurityConstants.DETAILS_USER_ID, String.valueOf(SecurityContextHolder.getUserId()));
                requestTemplate.header(SecurityConstants.DETAILS_USERNAME, SecurityContextHolder.getUserName());
                requestTemplate.header(SecurityConstants.USER_KEY, SecurityContextHolder.getUserKey());
            }
        };
    }
}